package org.workdemo.back.service.Impl;

import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;
import org.workdemo.back.entity.DTO.BackPageQueryDTO;
import org.workdemo.back.entity.DzyhThb;
import org.workdemo.back.entity.result.PageResult;
import org.workdemo.back.mapper.BackMapper;
import org.workdemo.back.service.BackService;

import javax.annotation.Resource;

/**
 * @author xxliang
 * @Date 2025/3/29 12:12
 */
@Service
@Slf4j
public class BackServiceImpl implements BackService {

    @Resource
    BackMapper backMapper;

    /**
     * 查询back信息
     *
     * @param gid
     * @return
     */
    @Override
    public DzyhThb getById(String gid) {
        return backMapper.getDzyhThbById(gid);
    }

    /**
     * 添加back信息
     *
     * @param dzyhThb
     */
    @Override
    public void addBack(DzyhThb dzyhThb) {
        log.info("将要执行添加操作");
        backMapper.addBack(dzyhThb);
    }

    /**
     * 依据gid删除退货信息
     *
     * @param gid
     */
    @Override
    public void deleteBack(String gid) {
        backMapper.deleteBack(gid);
    }


    /**
     * 修改退货申请
     *
     * @param dzyhThb
     */
    @Override
    public void updateBack(DzyhThb dzyhThb) {
        System.out.println(dzyhThb);
        backMapper.updateBack(dzyhThb);
    }

    /**
     * 分页查询
     *
     * @param backPageQueryDTO
     * @return
     */
    @Override
    public PageResult pageQuery(BackPageQueryDTO backPageQueryDTO) {
        //开始分页查询
        PageHelper.startPage(backPageQueryDTO.getPage(), backPageQueryDTO.getPageSize());
        //获取分页结果
        Page<DzyhThb> page = backMapper.pageQuery(backPageQueryDTO);
        long total = page.getTotal();
        return new PageResult(page.size(), page.getResult());
    }
}
